/****************************************************************************
*                                                                           *
* drawshape.h - scattering simulator			                            *
*                                                                           *
* ALaRI 2008												                *
*                                                                           *
****************************************************************************/
#pragma once

#if !defined(__DRAWSHAPE_H)
#define __DRAWSHAPE_H

/****************************************************************************
* Includes										                            *
****************************************************************************/
#include "../../common/defs.h"
#include <QRect>
#include <QLine>
#include <QColor>
#include <QPoint>

/****************************************************************************
* Forward declaration							                            *
****************************************************************************/
class QString;
/****************************************************************************
* CDrawShape									                            *
****************************************************************************/
class CDrawShape
{
public :

	enum eType 
	{ 
		eInvalidShape = -1,
		eLine,
		eRectangle, 
		eEllipse,
		ePoint
	};
	
	static const int s_nShapeHandleWidthDefault = 6;
	static const int s_nShapeHandleWidthPoint	= 10;

	/****************************************************************************
	* Constraction/Destruction						                            *
	****************************************************************************/
	CDrawShape(QString strName, eType type, const QRect& rRect, 
		const QColor& color, int nWidth)
		: m_strName(strName), m_type(type), m_rect(rRect), m_color(color), m_nWidth(nWidth)
	{}

	virtual ~CDrawShape()
	{}

	inline QRect rect() const { return m_rect; }
	inline int getWidth() const { return m_nWidth; } 
	inline eType type() const { return m_type;}
	inline const QString& getName() const { return m_strName; }
	inline void setName(const QString& strName) { m_strName = strName; } 
	inline QString name() { return m_strName; } 
	inline const QColor& getColor() const { return m_color; }
	inline void setColor(QColor& color) { m_color = color; } 
	inline void setWidth(int nWidth) { m_nWidth = nWidth;} 
	inline QRect shapeHandle() { return m_rectHandle; }
	
	virtual void reshape(const QPoint& rPoint) = 0;
	static void setBoundingRect(int nWidth, int nHeight)
	{ m_sRectBound = QRect(0, 0, nWidth, nHeight);}

protected :
	virtual void computeShapeHandle() = 0;
	void adjustHandle();
	// bounding rectangular of the shape
	QRect				m_rect;
	// type of the shape
	eType				m_type;
	// color
	QColor				m_color;
	// a unique name 
	QString				m_strName;
	// width 
	int					m_nWidth;
	// shape handle
	QRect				m_rectHandle; 
	// bounds
	static QRect		m_sRectBound;

};

/****************************************************************************
* CDrawLine																	*
****************************************************************************/
class CDrawLine :
	public CDrawShape,
	public QLine
{
public :
	CDrawLine(const QLine& rLine, const QColor& rColor, int nWidth)
		: QLine(rLine), 
		CDrawShape(QString("Line"), CDrawShape::eLine, QRect(rLine.p1(), rLine.p2()), 
				rColor, nWidth)
	{ computeShapeHandle(); }

	~CDrawLine()
	{}

	inline void reshape(const QPoint& rPoint) { setP2(rPoint); }

protected :
	void computeShapeHandle();
};

/****************************************************************************
* CDrawRect																	*
****************************************************************************/
class CDrawRect :
	public CDrawShape,
	public QRect
{
public :
	CDrawRect(const QRect& rRect, const QColor& rColor, int nWidth)
		: QRect(rRect), 
		CDrawShape(QString("Rect"), CDrawShape::eRectangle, rRect, rColor, nWidth)  
	{ computeShapeHandle(); }
	
	~CDrawRect()
	{}

	inline void reshape(const QPoint& rPoint) { setBottomRight(rPoint); }

protected :
	void computeShapeHandle();
};

/****************************************************************************
* CDrawEllipse																*
****************************************************************************/
class CDrawEllipse :
	public CDrawShape,
	public QRect
{
public :
	CDrawEllipse(const QRect& rRect, const QColor& rColor, int nWidth)
		: QRect(rRect), 
		CDrawShape(QString("Ellipse"), CDrawShape::eEllipse, rRect, rColor, nWidth)  
	{ computeShapeHandle(); }

	~CDrawEllipse()
	{}

	inline void reshape(const QPoint& rPoint) {	setBottomRight(rPoint); }

protected :
	void computeShapeHandle();
};

/****************************************************************************
* CDrawPoint																*
****************************************************************************/
class CDrawPoint :
	public CDrawShape,
	public QPoint
{
public :
	CDrawPoint(const QPoint& rPoint, const QColor& rColor, int nWidth)
		: QPoint(rPoint), 
		CDrawShape(QString(""), CDrawShape::ePoint, QRect(rPoint, rPoint), rColor, nWidth)  
	{ computeShapeHandle(); }

	~CDrawPoint()
	{
	}

	inline void reshape(const QPoint& rPoint) {}

protected :
	void computeShapeHandle();
};

#endif /* __DRAWSHAPE_H */
/****************************************************************************
* End of file																*
****************************************************************************/